import React, { useEffect, useState } from 'react'
import axios from 'axios'
import { withRouter } from 'react-router-dom';

 function Nowplaying(props) {
    const [list, setlist] = useState([]);
    useEffect(()=>{
        axios({
            url:'/api/mmdb/movie/v3/list/hot.json?ct=%E5%B9%BF%E5%B7%9E&ci=20&channelId=4'
        }).then(res =>{
            setlist(res.data.data.hot);
        })
    },[])
    var handleClick = (id) =>{
        props.history.push(`/detail/${id}`)    //编程式导航
    }
  return (
    <ul>
        {list.map(item =>
            <li key={item.videoId} onClick={()=>{
                handleClick(item.videoId);
            }}>
                {item.nm}
            </li>)}
    </ul>
  )
}

export default withRouter(Nowplaying);